function User(unfield,pwfield,pwvfield,emfield,emvfield)
{
	this.USERNAME_MIN_LEN = 2;
	this.USERNAME_MAX_LEN = 16;
	this.PASSWORD_MIN_LEN = 6;
	
	this.mUsernameElem = unfield[0];
	this.mPasswordElem = pwfield[0];
	this.mPassVerifyElem = pwvfield[0];
	this.mEmailElem = emfield[0];
	this.mEmailVerifyElem = emvfield[0];
	
	this.usernameAvailable = function(callback)
	{
		var uname = $.trim(this.mUsernameElem.value);
		ajaxPost('forum/core/user/user.php',{'action':'unamecheck','username':uname},function(resp)
		{
			if(resp.valid)
			{
				callback(resp);
			}
			else
			{
				callback({'valid':false,'reason':resp.error});
			}
		});
	};
	
	this.usernameValid = function(callback)
	{
		var uname = this.mUsernameElem.value;
		if(uname.length >= this.USERNAME_MIN_LEN)
		{
			if(uname.length <= this.USERNAME_MAX_LEN)
			{
				callback({'valid':true});
			}
			else
			{
				callback({'valid':false,'reason':'Username too long'});
			}
		}
		else
		{
			callback({'valid':false,'reason':'Username too short'});
		}
	};

	this.passwordValid = function(callback)
	{
		var pass = this.mPasswordElem.value;
		var pass_v = this.mPassVerifyElem.value;
		
		if(pass != '' && pass_v != '')
		{
			if(pass == pass_v)
			{
				if(pass.length >= this.PASSWORD_MIN_LEN)
				{
					callback({'valid':true});
				}
				else
				{
					callback({'valid':false,'reason':'Password too short'});
				}
			}
			else
			{
				callback({'valid':false,'reason':'Passwords do not match'});
			}
		}
	};

	this.emailValid = function(callback)
	{
		var email = this.mEmailElem.value;
		var email_v = this.mEmailVerifyElem.value;
		
		if(email != '' && email_v != '')
		{
			if(email == email_v)
			{
				if(email.indexOf('@') >= 0 && email.indexOf('.') >= 0)
				{
					callback({'valid':true});
				}
				else
				{
					callback({'valid':false,'reason':'Not a real email address'});
				}
			}
			else
			{
				callback({'valid':false,'reason':'Emails do not match'});
			}
		}
	};
	
	this.register = function(callback)
	{
		var uname = this.mUsernameElem.value;
		var pass = this.mPasswordElem.value;
		var pass_v = this.mPassVerifyElem.value;
		var email = this.mEmailElem.value;
		var email_v = this.mEmailVerifyElem.value;
		
		ajaxPost('forum/core/user/user.php',{'action':'newuser','username':uname,'password':pass,'password-v':pass_v,'email':email,'email-v':email_v},function(resp){
			if(resp.valid)
			{
				callback(resp);
			}
			else
			{
				callback({'valid':false,'reason':resp.error});
			}
		});
	}
	
	return true;
}